package com.atguigu.day14.exer.e1;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/16 10:30
 * @注释
 */
public enum Month {
    JANUARY("一月"),
    FEBRUARY("二月"),
    MARCH("三月"),
    APRIL("四月"),
    MAY("五月"),
    JUNE("六月"),
    JULY("七月"),
    AUGUST("八月"),
    SEPTEMBER("九月"),
    OCTOBER("十月"),
    NOVEMBER("十一月"),
    DECEMBER("十二月");
    private String description;

    Month(String description) {
        this.description = description;
    }

    public static Month getByValue(int value) {
        Month[] months = Month.values();
        return months[value - 1];
        /*switch (value) {
            case 1:
                return JANUARY;
            case 2:
                return FEBRUARY;
            case 3:
                return MARCH;
            case 4:
                return APRIL;
            case 5:
                return MAY;
            case 6:
                return JUNE;
            case 7:
                return JULY;
            case 8:
                return AUGUST;
            case 9:
                return SEPTEMBER;
            case 10:
                return OCTOBER;
            case 11:
                return NOVEMBER;
            case 12:
                return DECEMBER;
            default:
                return null;
        }*/
    }

    public int length(boolean leapYear) {
        int day = switch (this) {
            case JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER -> 31;
            case FEBRUARY -> leapYear ? 29 : 28;
            case APRIL, JUNE, SEPTEMBER, NOVEMBER -> 30;
        };
        return day;
    }

    @Override
    public String toString() {

        return (this.ordinal()+1) + "->" + this.name() + "->" + description;
    }
}
